package online.inote.modules.user.controller;

import java.util.Map;

import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import online.inote.common.utils.BaseResultFactory.ResultEnum;
import online.inote.common.utils.ResultFactory;
import online.inote.modules.user.entity.UserEntity;
import online.inote.modules.user.valid.ValidSaveUser;
import online.inote.modules.user.valid.ValidUpdateUser;

/**
 * <p>
 * Desc: 
 * </p>
 *
 * @author XQF SUI
 * @created 2018年9月4日 下午9:51:46
 * @version 1.0
 */
@RestController
@RequestMapping(value = "user")
public class UserController {

	/**
	  * <p>
	  * Desc: 保存
	  * </p>
	  *
	  * @author XQF SUI
	  * @created 2018年9月4日 下午9:52:38
	  * @return
	 */
	@PostMapping(value = "save")
	public Map<String, Object> save(@Validated(ValidSaveUser.class) UserEntity user, BindingResult result) {
		
		if(result.hasErrors()){
			return ResultFactory.createResultMap(ResultEnum.FAIL, result);
        }
		
		return ResultFactory.createResultMap(ResultEnum.SUCCESS);
	}
	
	/**
	  * <p>
	  * Desc: 更新
	  * </p>
	  *
	  * @author XQF SUI
	  * @created 2018年9月5日 上午12:01:03
	  * @param user
	  * @param result
	  * @return
	 */
	@PostMapping(value = "update")
	public Map<String, Object> update(@Validated(ValidUpdateUser.class) UserEntity user, BindingResult result) {
		
		if(result.hasErrors()){
			return ResultFactory.createResultMap(ResultEnum.FAIL, result);
        }
		
		return ResultFactory.createResultMap(ResultEnum.SUCCESS);
	}
}